import axios from 'axios';
import {ALL_SERVICE_API} from '../api';
var qs = require('qs');
// 获取短信模板数据
export const getSmsTemplets = params => {
  return axios.get(ALL_SERVICE_API + '/smstemplets', {params: params});
};

// 根据阿里id获取短信模板数据
export const getSmsTemplet = params => {
  return axios.get(ALL_SERVICE_API + '/smstemplet_by_templet_type', {params: params});
};

// 根据id删除群发短信
export const deletGroupSend = id => {
  return axios.delete(ALL_SERVICE_API + '/sms-group-send-plans/' + id);
};

// 修改群发短信状态为已审核
export const changeStatus = id => {
  return axios.post(ALL_SERVICE_API + '/sms_group_send_plan/change_status_by_id', qs.stringify({id: id}));
};

// 获取脚本数据
export const getSmsScripts = params => {
  return axios.get(ALL_SERVICE_API + '/smsvariableresolvers', {params: params});
};

// 保存模板数据
export const saveSmsTemplet = (params) => {
  return axios.post(ALL_SERVICE_API + '/smstemplets', params);
};

// 修改模板的保存
export const modifySmsTemplet = (params) => {
  return axios.put(ALL_SERVICE_API + '/smstemplet', params);
};

// 保存脚本数据
export const saveSmsScript = (params) => {
  return axios.put(ALL_SERVICE_API + '/sms-variable-resolvers', params);
};

// 删除模板
export const deleteSmsTemplet = params => {
  return axios.delete(ALL_SERVICE_API + '/sms-templets/' + params);
};

// 删除脚本
export const deleteSmsScript = id => {
  return axios.delete(ALL_SERVICE_API + '/sms-variable-resolvers/' + id);
};

// 根据模板ID查询映射bean
export const getMappingByTempletId = (templetId) => {
  return axios.get(ALL_SERVICE_API + '/smstemplet/mappingbytempletid?templetId=' + templetId);
};

// 将选中的模板列表和脚本列表保存并更新在数据库
export const postNewMapping = (templets, variables) => {
  return axios.post(ALL_SERVICE_API + '/saveandupdatenewmapping', qs.stringify({templets: templets, variables: variables}));
};

// 生成新的短信
// export const buildNewSMS = (phone, type) => {
//   return axios.post(API_NEW_VERSION + 'smstemplet_constant', qs.stringify({phone: phone, type: type}));
// };

// 获取收件箱列表
export const searchSendSms = params => {
  return axios.get(ALL_SERVICE_API + '/sms-out-boxes', {params: params});
};

// 获取群发短信计划列表
export const getSmsGroupSendPlan = params => {
  return axios.get(ALL_SERVICE_API + '/sms-group-send-plans', {params: params});
};

// 新增短信群发计划
export const saveNewGroupSendPlan = (params) => {
  return axios.put(ALL_SERVICE_API + '/sms-group-send-plans', params);
};

// 短信群发增加接收电话列表
export const saveAcceptPhones = (groupSendId, phones) => {
  return axios.post(ALL_SERVICE_API + '/sms_group_send_plan/save_phones', qs.stringify({groupSendId: groupSendId, phones: phones}));
};

// 短信群发增加接收电话列表(全部查询结果都添加)
export const saveAllPersonalsForSendPlan = (filters, sendPlanId) => {
  return axios.post(ALL_SERVICE_API + '/sms_group_send_plan/save_all_phones', qs.stringify({filters: filters, sendPlanId: sendPlanId}));
};

// 短信群发删除接收电话列表记录
export const deleteAcceptPhones = params => {
  return axios.delete(ALL_SERVICE_API + '/sms_group_send_plan/delete_phones', {params: params});
};

// 获取短信群发的接收电话列表
export const getAcceptPhones = params => {
  return axios.get(ALL_SERVICE_API + '/sms_group_send_plan/get_phones', {params: params});
};

// 获取短信群发的接收电话列表_不分页
// export const searchAcceptPhonesNoPage = params => {
//   return axios.get(ALL_SERVICE_API + '/sms_group_send_plan/get_phones/no_page', {params: params});
// };

// 测试发送短信
export const testSend = (groupSendId, phone) => {
  return axios.post(ALL_SERVICE_API + '/sms_group_send', qs.stringify({groupSendId: groupSendId, phone: phone}));
};

// 群发短信
export const groupSendSms = (groupSendId) => {
  return axios.post(ALL_SERVICE_API + '/sms_group_send/group', qs.stringify({groupSendId: groupSendId}));
};

// 群发短信
// export const sendSmsAll = params => {
//   return axios.post(API_NEW_VERSION + 'smsoutboxs/all', {params: params});
// };

// 刪除發件箱
// export const deleteSendBox = params => {
//   return axios.delete(API_NEW_VERSION + 'smsoutbox_delet', {params: params});
// };

// 向选择的用户发送短信
// export const batchSendSMs = (id) => {
//   return axios.post(API_NEW_VERSION + 'batchsendsmsoutboxs?id=' + id);
// };

// 根据群发计划id获取导入的电话
export const getSendPhonesByPlanId = (params) => {
  return axios.get(ALL_SERVICE_API + '/sms_group_send_plan/get_import_phones', {params: params});
};
